<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>我的文章</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <el-radio-group v-model="formData.is_examine" size="small" class="mb-10" @change="tabList">
          <el-radio-button :label="1">发布文章</el-radio-button>
          <el-radio-button :label="2">驳回文章</el-radio-button>
        </el-radio-group>
        <el-table
            ref="multipleTable"
            :data="arryList"
            :stripe="tableStyle.tableStripe"
            :border="tableStyle.tableBorder"
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
            header-cell-class-name="table-text-c"
            cell-class-name="table-text-c">
          <el-table-column
              align="center"
              prop="title"
              label="文章标题">
          </el-table-column>
          <el-table-column
              align="center"
              label="版块">
            <template slot-scope="scope">
              {{scope.row.plate.name}}
            </template>
          </el-table-column>
          <el-table-column
              prop="create_time"
              align="center"
              label="发布时间">
          </el-table-column>
          <el-table-column
              prop="comment_number"
              align="center"
              label="评论数"
              v-if="formData.is_examine==1"
              key="1">
          </el-table-column>
          <el-table-column
              prop="laud"
              align="center"
              label="点赞数"
              v-if="formData.is_examine==1"
              key="2">
          </el-table-column>
          <el-table-column
              prop="content"
              align="center"
              label="驳回理由"
              v-if="formData.is_examine==2"
              key="3">
          </el-table-column>
          <el-table-column
              align="center"
              label="操作"
              width="180">
            <template slot-scope="scope">
              <el-button size="small" @click="gotolist(scope.row.id)">详情</el-button>
              <el-button plain type="danger" size="small" @click="detelelist(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-col :span="24" class="toolbar">
          <el-pagination
              background
              layout="total, prev, pager, next"
              :total="page.total"
              :page-size="page.pagesize"
              @current-change="handleSizeChange">
          </el-pagination>
        </el-col>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click="closePOpup" size="small">返回</el-button>
      </div>
    </div>
    <forumDetail :visible.sync="detailVisible" :detailId="detailId" detailType="1" @InitFn="InitFn"></forumDetail>
  </div>
</template>

<script>
import {pagination, tableoption} from '@/utils/util.js'
import forumDetail from "./forumDetail";
import {forumDelete} from "@/api/admin/forum"

export default {
  props: ['visible', 'licenceId'], // commoent 学生点评 collection 学生采集
  components: {
    forumDetail
  },
  data() {
    return {
      detailVisible: false,
      dialogVisible: false,
      tableStyle: tableoption,
      page: {
        pageindex: pagination.pageIndex,
        pagesize: pagination.pageSize,
        total: pagination.total
      },
      arryList: [],
      tableHeight: 0,
      detailId: 0,
      formData: {
        is_examine: 1,
        user_id: null,
        p: 1
      }
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if(this.visible){
        let n = this;
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          this.tableHeight = height - (51 + 50 + 20+42 + 51)
        })
        this.InitFn()
      }
    }
  },
  created() {
    // let n = this;
    // this.$nextTick(() => {
    //   let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
    //   this.tableHeight = height - (51 + 50 + 20+42 + 51)
    //   console.log('高度', this.tableHeight)
    // })
    // this.InitFn()
  },
  methods: {
    async InitFn() {
      this.formData.p = this.page.pageindex
      let data = await this.$post(this.api.forum_postings_index, this.formData);
      if (data.code === 0) {
        for (let i in data.list.data) {
          data.list.data[i].create_time = data.list.data[i].create_time.split(' ')[0]
        }
        this.arryList = data.list.data
        this.page.total = data.list.total
      } else {
      }
    },
    tabList () {
      //  radio1
      this.page.pageindex = 1
      this.arryList = []
      this.InitFn()
    },
    detelelist(item) {
      this.$confirm(`确定删除【${item.title}】文章，是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.checkSuccessFn(item.id)
      }).catch(() => {

      })
    },
    checkSuccessFn(id) {
      // 0待审核1审核2驳回 is_examine
      forumDelete({id: id}).then(res=>{
        console.log('删除成功！：', res)
        if(!res.code){
          this.$message.success(res.msg)
          this.InitFn()
        }else{
          this.$message.error(res.msg)
        }
      })
    },
    // 查看详情
    gotolist(id) {
      this.detailId = id;
      this.detailVisible = true;
      // type 1 列表进入 2 审核进入
      // this.$router.push('/forumdetail?type=2&id=' + id)
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
    // 分页
    handleSizeChange(val) {
      this.page.pageindex = val
      this.InitFn()
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.hearder-search {
  display: flex;
  align-items: center;
}
</style>


